package com.china08.yxyapi.util;

import com.china08.yxyapi.entity.db.res.YxyResResource;
import com.china08.yxyapi.repository.db.YxyResResourceRepository;

public class WeiKeConvertRetryUntil {

    public static void retry(String weikeId) {
        System.out.println("重置微课转化次数,微课Id:" + weikeId);
        try {
            YxyResResourceRepository yxyResResourceRepository = SpringContextUtil
                    .getBean(YxyResResourceRepository.class);
            YxyResResource resource = yxyResResourceRepository.findOne(weikeId);
            if (resource != null && resource.getConvertRetryTimes() < 6 && resource.getConvertStatus() == 3) {
                resource.setConvertRetryTimes(resource.getConvertRetryTimes() + 1);
                resource.setConvertStatus(0);
                yxyResResourceRepository.save(resource);
            }
        } catch (Exception e) {
            System.out.println("重置微课转化次数失败:" + e.getMessage());
            System.out.println(e);
        }
    }

}
